-
Notifications
You must be signed in to change notification settings - Fork 1k
USBSerial would not block on write if the USB inteface is not connected #444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hi @ghent360 |
Yep.
…On Sun, Feb 17, 2019 at 11:28 PM Frederic Pillon ***@***.***> wrote:
Hi @ghent360 <https://github.com/ghent360>
Thanks for the PR.
I guess it solve issue with Marlin FW ?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#444 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHxY1mkc_6DER27wTfL8uOJk0mAKRa9hks5vOlYjgaJpZM4bABDN>
.
|
Hi @ghent360
Will it handle the situation where the USB is first connected and then the
cable is disconnected without locking up? If I remember I had to check
lineState to prevent a lock up with the timer based CDC.
Karl
…On Mon, Feb 18, 2019 at 8:30 AM ghent360 ***@***.***> wrote:
Yep.
On Sun, Feb 17, 2019 at 11:28 PM Frederic Pillon ***@***.***
>
wrote:
> Hi @ghent360 <https://github.com/ghent360>
> Thanks for the PR.
> I guess it solve issue with Marlin FW ?
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <
#444 (comment)
>,
> or mute the thread
> <
https://github.com/notifications/unsubscribe-auth/AHxY1mkc_6DER27wTfL8uOJk0mAKRa9hks5vOlYjgaJpZM4bABDN
>
> .
>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#444 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AQ8NJL-3c1vZnH6mA-3GhxNpcG-O2IJmks5vOlaDgaJpZM4bABDN>
.
|
Let me write a little test to double check.
On Mon, Feb 18, 2019 at 12:00 AM Karl Andersson <[email protected]>
wrote:
… Hi @ghent360
Will it handle the situation where the USB is first connected and then the
cable is disconnected without locking up? If I remember I had to check
lineState to prevent a lock up with the timer based CDC.
Karl
On Mon, Feb 18, 2019 at 8:30 AM ghent360 ***@***.***> wrote:
> Yep.
>
> On Sun, Feb 17, 2019 at 11:28 PM Frederic Pillon <
***@***.***
> >
> wrote:
>
> > Hi @ghent360 <https://github.com/ghent360>
> > Thanks for the PR.
> > I guess it solve issue with Marlin FW ?
> >
> > —
> > You are receiving this because you were mentioned.
> > Reply to this email directly, view it on GitHub
> > <
>
#444 (comment)
> >,
> > or mute the thread
> > <
>
https://github.com/notifications/unsubscribe-auth/AHxY1mkc_6DER27wTfL8uOJk0mAKRa9hks5vOlYjgaJpZM4bABDN
> >
> > .
> >
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <
#444 (comment)
>,
> or mute the thread
> <
https://github.com/notifications/unsubscribe-auth/AQ8NJL-3c1vZnH6mA-3GhxNpcG-O2IJmks5vOlaDgaJpZM4bABDN
>
> .
>
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#444 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHxY1uUbRE09I-wGH6TlFaQ557Yh1GE0ks5vOl2JgaJpZM4bABDN>
.
|
So I tried this:
void setup() {
// put your setup code here, to run once:
SerialUSB.begin(115200);
Serial1.begin(115200);
}
void loop() {
for(int idx = 0; true; idx++) {
SerialUSB.println(idx);
Serial1.println(idx);
}
}
The Serial1 continues to print when the USB is disconnected. The USB
resumes after it gets re-connected.
https://photos.app.goo.gl/hiP9ZAKGDzBkLmBMA
On Mon, Feb 18, 2019 at 12:05 AM Venelin Efremov <[email protected]>
wrote:
… Let me write a little test to double check.
On Mon, Feb 18, 2019 at 12:00 AM Karl Andersson ***@***.***>
wrote:
> Hi @ghent360
>
> Will it handle the situation where the USB is first connected and then the
> cable is disconnected without locking up? If I remember I had to check
> lineState to prevent a lock up with the timer based CDC.
>
> Karl
>
>
>
>
>
> On Mon, Feb 18, 2019 at 8:30 AM ghent360 ***@***.***>
> wrote:
>
> > Yep.
> >
> > On Sun, Feb 17, 2019 at 11:28 PM Frederic Pillon <
> ***@***.***
> > >
> > wrote:
> >
> > > Hi @ghent360 <https://github.com/ghent360>
> > > Thanks for the PR.
> > > I guess it solve issue with Marlin FW ?
> > >
> > > —
> > > You are receiving this because you were mentioned.
> > > Reply to this email directly, view it on GitHub
> > > <
> >
> #444 (comment)
> > >,
> > > or mute the thread
> > > <
> >
> https://github.com/notifications/unsubscribe-auth/AHxY1mkc_6DER27wTfL8uOJk0mAKRa9hks5vOlYjgaJpZM4bABDN
> > >
> > > .
> > >
> >
> > —
> > You are receiving this because you are subscribed to this thread.
> > Reply to this email directly, view it on GitHub
> > <
> #444 (comment)
> >,
> > or mute the thread
> > <
> https://github.com/notifications/unsubscribe-auth/AQ8NJL-3c1vZnH6mA-3GhxNpcG-O2IJmks5vOlaDgaJpZM4bABDN
> >
> > .
> >
>
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> <#444 (comment)>,
> or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AHxY1uUbRE09I-wGH6TlFaQ557Yh1GE0ks5vOl2JgaJpZM4bABDN>
> .
>
|
I see where the problem is: this only handles the case where the cable is
yanked, but when connected there is something that reads the data on the PC.
If I close the terminal on the PC the HardwareSerial still stops printing.
Karl, what is it that you had to check?
~V
On Mon, Feb 18, 2019 at 12:15 AM Venelin Efremov <[email protected]>
wrote:
… So I tried this:
void setup() {
// put your setup code here, to run once:
SerialUSB.begin(115200);
Serial1.begin(115200);
}
void loop() {
for(int idx = 0; true; idx++) {
SerialUSB.println(idx);
Serial1.println(idx);
}
}
The Serial1 continues to print when the USB is disconnected. The USB
resumes after it gets re-connected.
https://photos.app.goo.gl/hiP9ZAKGDzBkLmBMA
On Mon, Feb 18, 2019 at 12:05 AM Venelin Efremov ***@***.***>
wrote:
> Let me write a little test to double check.
>
> On Mon, Feb 18, 2019 at 12:00 AM Karl Andersson ***@***.***>
> wrote:
>
>> Hi @ghent360
>>
>> Will it handle the situation where the USB is first connected and then
>> the
>> cable is disconnected without locking up? If I remember I had to check
>> lineState to prevent a lock up with the timer based CDC.
>>
>> Karl
>>
>>
>>
>>
>>
>> On Mon, Feb 18, 2019 at 8:30 AM ghent360 ***@***.***>
>> wrote:
>>
>> > Yep.
>> >
>> > On Sun, Feb 17, 2019 at 11:28 PM Frederic Pillon <
>> ***@***.***
>> > >
>> > wrote:
>> >
>> > > Hi @ghent360 <https://github.com/ghent360>
>> > > Thanks for the PR.
>> > > I guess it solve issue with Marlin FW ?
>> > >
>> > > —
>> > > You are receiving this because you were mentioned.
>> > > Reply to this email directly, view it on GitHub
>> > > <
>> >
>> #444 (comment)
>> > >,
>> > > or mute the thread
>> > > <
>> >
>> https://github.com/notifications/unsubscribe-auth/AHxY1mkc_6DER27wTfL8uOJk0mAKRa9hks5vOlYjgaJpZM4bABDN
>> > >
>> > > .
>> > >
>> >
>> > —
>> > You are receiving this because you are subscribed to this thread.
>> > Reply to this email directly, view it on GitHub
>> > <
>> #444 (comment)
>> >,
>> > or mute the thread
>> > <
>> https://github.com/notifications/unsubscribe-auth/AQ8NJL-3c1vZnH6mA-3GhxNpcG-O2IJmks5vOlaDgaJpZM4bABDN
>> >
>> > .
>> >
>>
>> —
>> You are receiving this because you were mentioned.
>> Reply to this email directly, view it on GitHub
>> <#444 (comment)>,
>> or mute the thread
>> <https://github.com/notifications/unsubscribe-auth/AHxY1uUbRE09I-wGH6TlFaQ557Yh1GE0ks5vOl2JgaJpZM4bABDN>
>> .
>>
>
|
Is there a way to check if usb/cdc is connected? |
Yeah, this is a complex issue. I added checking the DTR line value, which gets set when the terminal is open and reset when the terminal is closed. That makes it work almost all the time. Now the edge case is when the terminal is open, but the program on the PC does not actually read the serial data, then it locks again. In my Ubuntu I use minicom for serial port communication, when I try to exit, there is a confirmation dialog "Are you sure you want to exit", if I stay there long enough the STM32 lock again. If I exit quickly there is no issue, the DTR line is reset and the code stops sending data, but if I linger on the exit dialog, apparently minicom stops reading data from the virtual terminal, but the terminal port is not closed. What a bummer :-( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would propose also to add a new USBSerial
method:
Forgot my comment about isConnected()
.
This last variant works even if I linger in the minicom menus. |
If people can test this change with different boards and host environments. Look for this #444 (comment) for an example test sketch. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you also made some commit clean up by squashing some of them.
At this time, this PR should only have 4 commits:
Do not block writes...
Return the correct bytes written
Check DTR value
Check if the last packet transfer ...
You can refers to contributing.md about PR wow and commit message tips.
Thanks in advance
I'm going on vacation tomorrow. I'll continue working on this PR when I come back at the end of the week. |
I've tried the changes in this PR and this resolves the issue I had with Marlin where the firmware would hang until the serial port is opened on the host side. On a side note, do you think there is any way that we could have a "serial disconnected" event that we could use within marlin to reset the board if the CDC port is closed/disconnected? Thanks! |
I was thinking about that for a bit, but it is not elegant approach,
because when the board is restarted the usb device is
disconnected/reconnected and it can result in a circular board reset
behavior:
Board starts;
USB is connected;
Port is open;
Board is reset;
Go to 1
…On Thu, Feb 21, 2019 at 4:36 PM Karl Andersson ***@***.***> wrote:
@ghent360 <https://github.com/ghent360>
I've tried the changes in this PR and this resolves the issue I had with
Marlin where the firmware would hang until the serial port is opened on the
host side.
On a side note, do you think there is any way that we could have a "serial
disconnected" event that we could use within marlin to reset the board if
the CDC port is closed/disconnected?
Thanks!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#444 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHxY1gxq8jOj3ruH3mfJ0QAASbVdv8gjks5vPxFsgaJpZM4bABDN>
.
|
why the serial assistant on PC can't receive data with follow sketch:
Only when I add this line "if (SerialUSB.available() > 0)", then send some data with serial assistant on PC, the PC can receive data continusly. |
@roc2 this is not clear. Which board? Core version (1.5.0, master,...)? With this PR applied or not?.... |
@fpistm My board is Black F407VE, core version 1.5.0. |
As it is done in Arduino for the Due.
|
Currently not. I only need to review it and test deeply. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some questions/remarks else code LGTM.
Currently, some tests on going.
@ghent360 I've made several test on several boards with different STM32 families and host OS. |
8318da3
to
8bf279d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not build.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Will do some other tests
Thanks @ghent360 |
Using your sketch #444 (comment) |
Update: |
Does my change affect the enumeration?
…On Tue, Mar 12, 2019 at 3:13 AM Frederic Pillon ***@***.***> wrote:
Under Windows, Unable to recognized the device after unplug/plug. Enum
failed.
Update:
Doing further investigations, if I didn't open a terminal on the COM port.
Enumeration is correct each time.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#444 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AHxY1ply-75_yKZctstBm8A5Ur1DR4apks5vV33igaJpZM4bABDN>
.
|
No @ghent360 , this is better with this PR. Trying Teraterm, if I well disconnect, then it's ok. This seems very linked to the driver and how Windows handle the COM... |
USBSerial would not block on write if the USB inteface is not connected
No description provided.